home *** CD-ROM | disk | FTP | other *** search
File List | 1997-06-08 | 4.7 KB | 149 lines |
- ' GFA-BAsic Example Code for STiK v1.08
- ' by Lonny Pursell
- ' (C)1997 by Lonny Pursell and ENCOM
- ' All rigths reserved.
- ' Date: 6/8/97
- ' E-Mail: atari@bright.net
- '
- ' ==============================================================================
- ' NOTE: This is not meant to be executed and is only an example of STiK access!
- ' ==============================================================================
- '
- $C+ !save/restore registers when using the C:() function
- ' ------------------------------------------------------------------------------
- ' ** init_stik()
- status&=@init_stik !this routine must be called once before any STiK access
- SELECT status&
- CASE 0
- PRINT "STiK access is granted"
- CASE -1
- PRINT "SYSTEM HAS NO COOKIE JAR"
- CASE -2
- PRINT "STiK NOT FOUND"
- CASE -3
- PRINT "STiK IS DISABLED"
- CASE -4
- PRINT "STiK MAGIC NOT FOUND"
- CASE -5
- PRINT "TRANSPORT LAYER NOT LOADED"
- ENDSELECT
- ' ------------------------------------------------------------------------------
- ' ** version$()
- vn$=@version$
- PRINT "STiK version is ";vn$
- ' ------------------------------------------------------------------------------
- ' ** resolve()
- domain$="post.demon.co.uk" !server to fetch ip address of
- ip%=0 !this will hold the ip address when resolve() returns
- result&=@resolve(domain$,0,V:ip%,1)
- IF result&=1 !we got an ip address?
- ' function ip_str$() simply displays the ip% address in dotted decimal
- PRINT "the ip address of ";domain$;" is ";@ip_str$(ip%)
- ELSE
- PRINT "resolve() failed"
- PRINT @get_err_text$(result&)
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** tcp_open()
- ch&=@tcp_open(ip%,139,0,1024)
- ' ch&=@tcp_open(0,0,0,1024) !this would be a listen socket
- IF ch&=>0 !connection opened?
- PRINT "the connection handle returned is ";ch&
- ELSE
- PRINT "tcp_open() failed"
- PRINT @get_err_text$(ch&)
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** cngetinfo()
- cib%=@cngetinfo(ch&) !get pointer to structure
- IF cib%>0 !valid pointer?
- PRINT "local port is ";CARD{cib%+2}
- ELSE
- PRINT "bad connection handle"
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** tcp_wait_state()
- status&=@tcp_wait_state(ch&,4,60) !the 4 means wait for connection established
- IF status&<0
- PRINT "tcp_wait_state() failed"
- PRINT @get_err_text$(status&)
- ELSE
- PRINT "connection established"
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** tcp_send()
- buf$="Send this line out the connection"
- status&=@tcp_send(ch&,V:buf$,LEN(buf$))
- IF status&<0
- PRINT "tcp_send() failed"
- PRINT @get_err_text$(status&)
- ELSE
- PRINT LEN(buf$);" bytes of data sent on connection ";ch&
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** cnbyte_count()
- count&=@cnbyte_count(ch&)
- IF count&<0
- PRINT "error detected"
- PRINT @get_err_text$(count&)
- ELSE IF status&=0 !no data?
- PRINT "no data came in yet on connection ";ch&
- ELSE IF count&>0 !we got data?
- PRINT count&;" bytes came in on connection ";ch&
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** cnget_char()
- count&=@cnbyte_count(ch&)
- IF count&>0
- char&=@cnget_char(ch&)
- IF char&=>0 !we got data?
- PRINT "one byte (";char&;") fetched from connection ";ch&
- ELSE
- PRINT "error detected"
- PRINT @get_err_text$(char&)
- ENDIF
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** cnget_block()
- count&=@cnbyte_count(ch&)
- IF count&>0
- buf$=SPACE$(count&) !create a buffer
- status&=@cnget_block(ch&,V:buf$,count&)
- IF status&<0
- PRINT "error detected"
- PRINT @get_err_text$(status&)
- ELSE IF status&>0 !we got data?
- PRINT count&;" bytes fetched from connection ";ch&
- ENDIF
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** tcp_close()
- status&=@tcp_close(ch&,5)
- IF status&<0
- PRINT "tcp_close() failed"
- PRINT @get_err_text$(status&)
- ELSE
- PRINT "connection closed"
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** getvstr$()
- tag$="ALLOCMEM"
- d$=@getvstr$(tag$)
- IF LEN(d$)>0
- PRINT "tag ";tag$;" is set to ";d$
- ELSE
- PRINT "tag ";tag$;" is not set or missing"
- ENDIF
- ' ------------------------------------------------------------------------------
- ' ** carrier_detect()
- cd&=@carrier_detect
- IF cd&=-1
- PRINT "carrier not detected"
- ELSE IF cd&=0
- PRINT "carrier detect unknown"
- ELSE IF cd&=1
- PRINT "carrier is detected"
- ENDIF
- ' ------------------------------------------------------------------------------
- ' eof
-